package com.ruoyi.framework.dataPermission;

import com.ruoyi.common.annotation.DataPermission;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
@Aspect
@Component
public class SpringDataPermissionAop implements InitializingBean {

    @Pointcut("@annotation(com.ruoyi.common.annotation.DataPermission)")
    public void pointcut() {

    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint point) throws Throwable{
        try{
            MethodSignature signature = (MethodSignature) point.getSignature();
            Method method = signature.getMethod();
            DataPermissionHolder.setDataPermission(method.getAnnotation(DataPermission.class));
            return point.proceed();
        }finally {
            DataPermissionHolder.removeDataPermission();
        }
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println(12313);
    }
}
